<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Youzi
 * Date: 12-11-14
 * Time: 下午9:13
 * To change this template use File | Settings | File Templates.
 */
class AttendanceArrangeModel extends Model
{
    static  $_instance   = null;
    private $_table     = 'crm_attendance_arrange';

    static function getInstance()
    {
        if (is_null(self::$_instance)) {
            self::$_instance = new self();
        }
        return self::$_instance;
    }

    /**
     * 考勤特殊安排列表
     *
     * @param  string $sorts
     * @param  int  $page
     * @param  int  $pagesize
     * @return array
     */
    public function getList($sorts = 'id', $page = 0, $pagesize = 10)
    {
        $list = $this->sql('select * from '.$this->_table.' where stop=0 order by '.$sorts.' desc')->s();
        return $list;
    }

    /**
     * 添加考勤特殊安排
     *
     * @param  array    $data
     * @return bool
     */
    public function add($data)
    {
        $sql = insertSql($this->_table, $data);
        return $this->sql($sql)->i();
    }

    /**
     * 修改考勤特殊安排
     *
     * @param  array    $data
     * @param  int      $id
     * @return bool
     */
    public function edit($data, $id)
    {
        $sql = updateSql($this->_table, $data, 'id='.$id);
        return $this->sql($sql)->u();
    }

    /**
     * 删除考勤特殊安排
     *
     * @param  int  $id
     * @return bool
     */
    public function del($id)
    {
        $sql = "delete from ".$this->_table." where id=".$id;
        return $this->sql($sql)->d();
    }

    /**
     * 获取考勤特殊安排详情
     *
     * @param  int  $id
     * @return array
     */
    public function getInfo($id)
    {
        $row = $this->sql('select * from '.$this->_table.' where id= '.$id)->s(1);
        return $row;
    }
}
